package test.kit.hutool._6_annotation;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Getter;

import java.util.Objects;

public enum Status {
    UP_DOING(11, "上传中"),
    UP_SUCC(12, "上传成功"),
    UP_FAIL(13, "上传失败"),

    CVT_DOING(21, "转换中"),
    CVT_SUCC(22, "转换成功"),
    CVT_FAIL(23, "转换失败"),

    REC_DOING(31, "识别中"),
    REC_FINISH(32, "识别完成"),
    REC_FAIL(33, "识别失败");

    @Getter
    private int code;
    @Getter
    private String desc;

    Status(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static String desc(int code) {
        Status[] ss = values();
        String desc = null;
        for (Status s : ss) {
            if (NumberUtil.equals(code, s.code)) {
                desc = s.desc;
            }
        }
        if (Objects.isNull(desc)) {
            throw new IllegalArgumentException(StrUtil.format("{} 非法", code));
        }
        return desc;
    }

    @Override
    public String toString() {
        return StrUtil.format("{}:{}:{}", name(), code, desc);
    }
}
